/**
 * 监控浏览器大小

 */
$(window).resize(function() {
	if ($(window).width() < screen.width * 0.7) {
		$(".row-left").css("width", "100%");
		$(".row-right").css("width", "100%");
	} else {
		$(".row-left").css("width", "20%");
		$(".row-right").css("width", "77%");
	}
})
$(".main-center").scroll(function(){
	$('.try').css("display","none"); 
	$(".garbager-option").css("display","none");
})

$(function(){
	$(".row-left").click(function(){
		$(".newname-hide").css("display","none");
	})
	$(".tab-content-folder").on("mouseover mouseout",".tab-content-folder-one",function(e){			
		 	if(e.type == "mouseover"){
			  //鼠标悬浮
		 		$(this).css("background-color","#f1f5fa") ;
				$(this).css(" border","1px solid #f1f5fa") ;   
		 		$(this).parent().css("background-color","#f1f5fa") ;
		 		$(this).parent().css(" border","1px solid #f1f5fa") ;
		 		$(this).children(".select-icon").css("display","block");			 
			}else if(e.type == "mouseout"){
			  //鼠标离开
				if($(this).children(".select-icon").hasClass("block")){
					$(this).children(".select-icon").css("display","block");
				}else{
					$(this).children(".select-icon").css("display","none");
					$(this).css("background-color","transparent") ;
					$(this).css(" border","none") ;
				}	 	 	
			}
	})
	
	$(".tab-content-folder").on("click",".select-icon",function(){		
		if($(this).hasClass("block")){
			$(this).children().css("color","#bfd1ea");
			$(this).removeClass("block");				
		}else{
			$(this).css("display","block");
			$(this).parent().css("background-color","#f1f5fa") ;
			$(this).parent().css(" border","1px solid #f1f5fa") ;   
			$(this).children().css("color","#3b8cff");
			$(this).addClass("block");
		}
	})
	/**
	 * 全选
	 */
	$(".icheckbox").click(function(){
			if($(this).attr("aria-checked")=="false"){
				$(this).addClass("icheckbox_flat-green-checked");
				$(this).removeClass("icheckbox_flat-green");
				$(this).attr("aria-checked","true");				
			}else if($(this).attr("aria-checked")=="true"){
				$(this).addClass("icheckbox_flat-green");
				$(this).removeClass("icheckbox_flat-green-checked");
				$(this).attr("aria-checked","false");		
			};
		});	
	/**
	 * 文件和文件夹全选
	 */
	$(".checkbox-togger").click(function(e){
		var obj=$('.select-icon');
		var i=0;
		obj.each(function(){
			if($(this).hasClass("block")){
				i++;	
			}else{
				$(this).css("display","block");
				$(this).parent().css("background-color","#f1f5fa") ;
				$(this).parent().css(" border","1px solid #f1f5fa") ;   
				$(this).children().css("color","#3b8cff");
				$(this).addClass("block");
			}
		})
		if(obj.length==i){
			$(".select-icon").children().css("color","#bfd1ea");
			$(".select-icon").removeClass("block");	
			$(".select-icon").css("display","none");
			$(".select-icon").parent().css("background-color","transparent") ;
			$(".select-icon").parent().css(" border","none") ;
		}
	});
	/**
	 * 多选框图片更换
	 */
	$(".contacts-tables-div").on("click",".icheckbox",function(){
		if($(this).attr("aria-checked")=="false"){
			$(this).addClass("icheckbox_flat-green-checked");
			$(this).removeClass("icheckbox_flat-green");
			$(this).attr("aria-checked","true");
			
		}else if($(this).attr("aria-checked")=="true"){
			$(this).addClass("icheckbox_flat-green");
			$(this).removeClass("icheckbox_flat-green-checked");
			$(this).attr("aria-checked","false");
			
		};
	});	
	/**
	 * 鼠标移到表格内操作按钮的事件
	 */
	$(".tab-content .btn").mouseover(function(){
		$(this).find("span").show();
	});
	$(".tab-content .btn").mouseout(function(){
		$(this).find("span").hide();
	});
	
//右键文件夹事件
	$(".tab-content-folder").on('mousedown','.tab-content-folder-one',function(e){
		var objvalue=$(this).find(".ab-content-folder-one-name").find("a");
		  if(3 == e.which){ 
			  var obj=$(this).find(".select-icon");
			  if(obj.hasClass("block")){
					obj.children().css("color","#bfd1ea");
					obj.removeClass("block");				
				}else{
					obj.css("display","block");
					obj.parent().css("background-color","#f1f5fa") ;
					obj.parent().css(" border","1px solid #f1f5fa") ;   
					obj.children().css("color","#3b8cff");
					obj.addClass("block");
				}
			  e = e || window.event;			
			  var a=$(this).find("a");
			  var obj=$(this);
			  var x=e.pageX || e.clientX + document.body.scroolLeft;
			  var y=e.pageY || e.clientY + document.boyd.scrollTop;
			  var yy= $(this).offset().top;
			  var xx = $(this).offset().left;
			  $(".rename").attr("xx",xx);
			  $(".rename").attr("yy",yy);
			  
			/*  if($(this).attr("type")=="folder"){
				  if($(".fudai").hasClass("download")){
					  $(".fudai").css("color","blue");
					  $(".fudai").removeClass("download");
				  }
			  }else if($(this).attr("type")=="file"){
				  if(!$(".fudai").hasClass("download")){
					  $(".fudai").css("color","black");
					  $(".fudai").addClass("download");
				  }
			  }*/
			  if($(".tab-content-myfile").children("a:eq(0)").children("span").text().trim()=="回收站"){
				  if($(".main-left").width()>50){
					  $(".garbager-option").css("left",x-210+"px");
					  $(".garbager-option").css("top",y-40+"px");
				  }else{
					  $(".garbager-option").css("left",x-45+"px");
					  $(".garbager-option").css("top",y-40+"px");
				  }		  			  
				  $(".garbager-option").css("display","block");				 
			  }else{
				  if($(".main-left").width()>50){
					  $(".try").css("left",x-210+"px");
					  $(".try").css("top",y-40+"px");
				  }else{
					  $(".try").css("left",x-45+"px");
					  $(".try").css("top",y-40+"px");
				  }		  			  
				  $(".try").css("display","block");	
			  }		  
			  var direname=$(this).attr("directname");
			  var directid=$(this).attr("directid");
			  var filesuffix=$(this).attr("filesuffix");
			  var filepath=$(this).attr("filepath");
			  if(filesuffix==undefined){
				  filesuffix="undefined";							  
			  }
			  $(".download").attr("directid",directid);
			  $(".download").attr("filepath",filepath);
			  $(".download").attr("filesuffix",filesuffix);	
			  
			  $(".delete").attr("filesuffix",filesuffix);
			  $(".delete").attr("directid",directid);
			  
			  $(".open").attr("filesuffix",filesuffix);
			  $(".open").attr("filepath",filepath); 
			  
			  $(".copy").attr("filename",direname);
			  $(".copy").attr("filepath",filepath);
			  $(".copy").attr("filesuffix",filesuffix);
			  $(".copy").attr("directid",directid);
			  
			  $(".delete").attr("filesuffix",filesuffix);
			  $(".delete").attr("directid",directid);
			  
			  $(".move").attr("filesuffix",filesuffix);
			  $(".move").attr("directid",directid);
			  $(".move").attr("filename",direname);
			  $(".move").attr("filepath",filepath);
			  
			  $(".try-hide").css("display","none");
			  
			  $(".sharecompany").attr("filesuffix",filesuffix);
			  $(".sharecompany").attr("directid",directid);
			  
			  $(".shareuser").attr("filesuffix",filesuffix);
			  $(".shareuser").attr("directid",directid);	
			  
			  $(".rename").attr("dirid",directid);
			  $(".rename").attr("filesuffix",filesuffix);
			  $(".rename").attr("dirname",$(this).find(".ab-content-folder-one-name").find("a").text());
			  var text=$(".tab-content-myfile").children("a:eq(0)").children("span").text();
			  if(text=="公司文件"||text=="共享文件"){
				  $(".move").addClass("off");
				  $(".delete").addClass("off")
			  } else{
				  $(".delete").removeClass("off")
				  $(".move").removeClass("off");
			  }
		  }	
		   $(document).one("click",function(){
				$(".try").css("display","none");
				 $(".garbager-option").css("display","none");	
			});		 
		  e.stopPropagation();
	})	
	$(".rename").click(function(e){	
				var xx=$(this).attr("xx");
				var yy=$(this).attr("yy");
				var dirname= $(this).attr("dirname");
				var filesuffix= $(this).attr("filesuffix");
				var dirid= $(this).attr("dirid");
				var text=$(".tab-content-myfile").children("a:eq(0)").children("span").text();		
				  if(text=="公司文件"||text=="共享文件"){
					  var obj="\<\div style='width: 210px;height: auto; margin: 13% auto; text-align:center;'><span style='font-size:14px'>不能对此文件进行修改操作！！！</span>\<\/div>";
					  promptbox(obj);
				  }else{
				   $(".newname-hide").css("display","block");
				   $(".tab-content-folder-hide").css("display","block");
				   if($(".main-left").width()>50){
					   $(".newname-hide").css("left",xx-225+"px");						   			 
				   }else{
					   $(".newname-hide").css("left",xx-50+"px");	
				   }		
				   $(".newname-hide").css("top",yy-50+"px");		
				   $(".ab-content-folder-one-newname-input").val(dirname);
				   $(".yes").attr("dirid",dirid);
				   if(filesuffix!="undefined"){
					   $(".yes").attr("filesuffix",filesuffix);
				   }
				  }
				})		
	//重命名取消事件
	$(".no").click(function(){
		  $(".newname-hide").css("display","none");
		  $(".tab-content-folder-hide").css("display","none");
		  $(".ab-content-folder-one-newname-input").val("");
		  $(".yes").attr("dirid","");	  
	})
	$(".yes").click(function(){
		  var value=$(".ab-content-folder-one-newname-input").val();
		  var dirid=$(this).attr("dirid");
		  var filesuffix=$(this).attr("filesuffix");
		  
		  var obj=$(".tab-content-folder-one");
		  obj.each(function(){
			 if($(this).attr('directid')==dirid && $(this).attr('filesuffix')==filesuffix){
				 $(this).find(".ab-content-folder-one-name").find("a").text(value);
			 }
		  })
		  $.ajax({
			  	type:"post",
			  	url:"/file/newname",
				cache:false,
				async: false,
				traditional:true,
				data:{"dirid":dirid,"filesuffix":filesuffix,"value":value},				
				success:function(data){}		
		})
		  $(".newname-hide").css("display","none");
		  $(".tab-content-folder-hide").css("display","none");
		  $(".ab-content-folder-one-newname-input").val("");
	})
	 $(document).bind("contextmenu",function(e){
				 return false;
		});
	//右键点击事件
	$(".tab-content").mousedown(function(e){	
		  if(3 == e.which){ 
			  e = e || window.event;				
			  var x=e.pageX || e.clientX + document.body.scroolLeft;
			  var y=e.pageY || e.clientY + document.boyd.scrollTop;			  
			  $(".try-hide").css("left",x-210+"px");
			  $(".try-hide").css("top",y-40+"px");
			  $(".try-hide").css("display","block");
			  $(".try").css("display","none");
			  $(".newname-hide").css("display","none");
			   $(".tab-content-folder-hide").css("display","none");
          }
		  $(document).one("click",function(){
				$(".try-hide").css("display","none");								
		  });		 
	})	
//新建文件夹
	$(".newfolder").click(function(){
		newfolder();
	})
//刷新
	$(".filerefresh").click(function(e){
		refresh(e);
	})
//垃圾桶删除
	$(".delete-icon").click(function(){		
		var obj=$(".tab-content-myfile").children("a:eq(0)").children("span").text();
		if(obj!="公司文件"&&obj!="共享文件"&&obj.trim()!="回收站"){
		layer.confirm('删除后不可恢复，确认删除？',{closeBtn: 0},function(index){
		var file=[];
		var folder=[];
		var obj=$(".block");
		obj.each(function(){
			if($(this).attr("filesuffix")==undefined){
				folder.push($(this).attr("directid"));
			}else{
				file.push($(this).attr("directid"));	
			}
		})		
		if(folder.length==0){
			folder.push("undefiend");
		}
		if(file.length==0){
			file.push("undefiend");
		}
		$.ajax({
				type:"post",
				url:"/file/deleteicon",
				cache:false,
				async: false,
				traditional:true,
				data:{"file":file,"folder":folder},				
				success:function(data){}		
		})
		var fatherid=$(".tab-content-myfile a").last().attr("fatherid");
		var obj=$(".tab-content-myfile").children("a:eq(0)").children("span").text();
		$(".tab-content-folder").html("");
		ajax(fatherid);	
		layer.close(index);
		})
		}else if(obj.trim()=="回收站"){	
		layer.confirm('删除后不可恢复，确认删除？',{closeBtn: 0},function(index){
			var file=[];
			var folder=[];
			var obj=$(".block");
			obj.each(function(){
				if($(this).attr("filesuffix")==undefined){
					folder.push($(this).attr("directid"));
				}else{
					file.push($(this).attr("directid"));	
				}
			})
			realydelete(file,folder,"删除");	
		$(".tab-content-folder").html("");
		gabegediv();
		layer.close(index);
		})
		
		}else{
			var obj="\<\div style='width: 210px;height: auto; margin: 13% auto; text-align:center;'><span style='font-size:14px'>不能对此文件进行删除操作！！！</span>\<\/div>";  
			promptbox(obj);
		}						
})
//删除
	$(".delete").click(function(){
		$(".delete-icon").trigger("click");	
	})
	$(".realy-delete").click(function(){
		$(".delete-icon").trigger("click");	
	})
	//下载
	$(".download").click(function(e){		
		var directid= $(this).attr("directid");
		var filepath= $(this).attr("filepath");
		var filesuffix= $(this).attr("filesuffix");
		if(filesuffix=="undefined"){
			var obj="\<\div style='width: 210px;height: auto; margin: 13% auto;  text-align:center;'><span style='font-size:14px'>不支持文件夹下载！！！</span>\<\/div>";
			promptbox(obj);
			return;
		}	
		var reg = new RegExp("\\\\","g");		
		var path=filepath.replace(reg,'/');	
		window.open("/file/download/?directid="+directid+"&path="+path+"&filesuffix="+filesuffix+"");
	})
//上传文件
$(".fileup").change(function(){
	var fatherid=$(".tab-content-myfile a").last().attr("fatherid");
	var path=$(".tab-content-myfile a").last().attr("path");
	var formata=new FormData();			
	if($(".fileup")[0].files[0]!=null){				
	formata.append("image",$(".fileup")[0].files[0]);
	formata.append("dirId",fatherid);
	formata.append("path",path);
	
		$.ajax({
			type:"post",
			url:"/file/upload",
			cache:false,
			async: false,
			processData:false,
			contentType:false,
			data:formata,
			success:function(data){	
			layer.msg('上传成功',{shift: -1,time:1000}, function(){
			});						
		}
	});
	var obj=$(".tab-content-myfile").children("a:eq(0)").children("span").text();
	if(obj=="全部文件"){
		$(".tab-content-folder").html("");
		ajax(fatherid);
	}else{
		refreshPanel(getUrlPrefix("/file/file"),"文件管理");
	}
}		
	$(".fileup").val("");
})
//打开
$(".try").on("click",".open",function(){
	var height;
	var width;
	var filesuffix= $(this).attr("filesuffix");
	var filepath=$(this).attr("filepath");
	openfile(filesuffix,filepath);
})

//复制到
$(".copy").click(function(){
	var filename= $(this).attr("filename");
	var filepath= $(this).attr("filepath");
	var suffix=$(this).attr("filesuffix");	
	var fileid=$(this).attr("directid");
	//easyui建树
	$(".filetree-tree").tree({
		url:'/file/tree'
	});
copymove(fileid,filename,filepath,suffix,"/file/copyfile");
})

//移动到
$(".move").click(function(){	
	if($(this).hasClass("off")){
	
	}else{
	var filename= $(this).attr("filename");
	var filepath= $(this).attr("filepath");
	var suffix=$(this).attr("filesuffix");	
	var fileid=$(this).attr("directid");
	$(".filetree-tree").tree({
		url:'/file/tree'
	});
		copymove(fileid,filename,filepath,suffix,"/file/movefile");
	}
})

//查找指定人
$(".search-btn-shareuser").click(function(){
	var inputval=$(".search-btn-shareuser-input").val();
	$(".contacts-tables tbody").html("");
	if(inputval==""){	
		newalluser();
		return;
	}
	 $.ajax({
		  type:"post",
		  url:"/file/searchshareuser",
		  cache:false,
		  async:false,
		  data:{"inputval":inputval},
		  datatype:"json",
		  success:function(data){
		  $.each(data,function(i,item){
			  newtable(item);		  
			})
		}
	  })
})

//分享给指定人
$(".shareuser").click(function(){
	$(".search-btn-shareuser-input").val("")
	var suffix=$(".shareuser").attr("filesuffix");
	var directid=$(".shareuser").attr("directid");
	$(".contacts-tables tbody").html("");
	var ulist=[];
	newalluser();
	layer.open({
		  type: 1,
		  skin: 'demo-class',
		  skin: 'yourclass',
		  offset: '100px',
		  title :'联系人',
		  area: ['804px', '492px'], //宽高
		  content: $(".contacts-tables"),
		  closeBtn: 0,
		  btn:['确定', '取消'],
		  btnAlign: 'c', 
		  yes: function(index, layero){
			var obj= $(".icheckbox_flat-green-checked");
			obj.each(function(){
				ulist.push($(this).attr("data"));
			})
			$.ajax({
				type:"post",
				url:"/file/shareuser",
				cache:false,
				async: false,
				traditional:true,
				data:{"ulist":ulist,"suffix":suffix,"directid":directid},				
				success:function(data){}		
			})
			layer.close(index);
		  }
		,btn2: function(index, layero){
		   	layer.close(index);
		  }
	});
	
})
//打开文件夹
$(".tab-content-folder").on('dblclick','.tab-content-folder-one',function(){
	var text=$(".tab-content-myfile").children("a:eq(0)").children("span").text();
	if(text.trim()=="回收站"){
		var obj="\<\div style='width: 210px;height: auto; margin: 13% auto; text-align:center;'><span style='font-size:14px'>需还原文件才可进行操作！！！</span>\<\/div>";
		 promptbox(obj);
	}else{
		var directid=$(this).attr("directid");
		var direname=$(this).attr("directname");
		var path=$(this).attr("filepath");
		var suffix=$(this).attr("filesuffix");
		if(suffix==undefined){
			var son=$("<a href='javascript:void(0)' class='sonicon' fatherid='"+directid+"' path="+path+"><span style='margin-right:5px'>"+direname+"</span><i class='iconfont icon-play_fill' style='font-size: 14px;'></i></a>");
			$(".tab-content-myfile").append(son);
			$(".tab-content-folder").html("");
			ajax(directid);	
		}else{
			fileopen(suffix,path);	
		}
	}
})

$(".tab-content-myfile").on("click",".sonicon",function(){
var fatherid=$(this).attr("fatherid");
var text=$(".tab-content-myfile").children("a:eq(0)").children("span").text();
$(this).nextAll().remove();
$(".tab-content-folder").html("");
if(text=="公司文件"){	
	loadcompanyshare(null);
}else if(text=="共享文件"){
	loadusershare();
}else{
	 ajax(fatherid);
}

})
//选择文件类型
	$(".file-type").click(function(){
		var filetype=$(this).attr("filetype");
		var fatherid=$(this).attr("fatherid");
		var t;
		t=$(this).children("span").text();
		var obj=$(".tab-content-myfile").children("a:eq(0)");
		$(".tab-content-myfile").html("");	
		$(this).nextAll().remove();
		if(filetype=="allfile"){
			obj.children("span").text($(this).children("span").text());
			$(".tab-content-myfile").append(obj);
			$(".tab-content-folder").html("");
			$(".box-title").children("span").text(t);
			ajax(fatherid);	
			return;
		}else if(filetype=="gabage"){
			obj.children("span").text(t);
			$(".tab-content-folder").html("");
			$(".box-title").children("span").text(t);
			$(".tab-content-myfile").append(obj);
			gabegediv();
		}else{		
		$.ajax({
			type:"post",
			url:"/file/filetype",
			cache:false,
			async: false,
			data:{"filetype":filetype},
			datatype:"json",
			success:function(data){
				$(".tab-content-folder").html("");
				$.each(data,function(i,item){
					newdiv(item);
				})
			}			
		})
		obj.children("span").text(t);
		$(".box-title").children("span").text(t);
		$(".tab-content-myfile").append(obj);
		}
	})
	
//共享文件,公司文件
$(".filepermission").click(function(){
	var typename=$(this).attr("typename");
	var obj=$(".tab-content-myfile").children("a:eq(0)");
	$(".tab-content-myfile").html("");	
	obj.children("span").text(typename);
	$(".tab-content-myfile").append(obj);	
	$(".tab-content-folder").html("");
	if(typename=="共享文件"){
		loadusershare();
	}else{
		loadcompanyshare();
	}	
})	
//显示分享类型
$(".fileshare").hover(function(){
	$(".sharetype").css("display","block");
	$(".sharetype").css("color","black");
})
$(".fileshare").mouseleave(function(){
	$(".sharetype").css("display","none");
})


//分享给公司
$(".sharecompany").click(function(){
	var filesuffix=$(this).attr("filesuffix",filesuffix);
	var directid=$(this).attr("directid",directid);
	$.ajax({
		type:"post",
		url:"/file/share",
		cache:false,
		async: false,
		data:{"directid":directid,"filesuffix":filesuffix},
		success:function(data){			
		}	
	})
})
	//查找
	$(".search-btn-file").click(function(){
		var text=$(".tab-content-myfile").children("a:eq(0)").children("span").text();
		var value=$(".search-input").val();
		
		if(value==""||value==null){
			var obj="\<\div style='width: 210px;height: auto; margin: 13% auto;  text-align:center;'><span style='font-size:14px'>查询不能为空！！！</span>\<\/div>";
			promptbox(obj);
			return;
		}		
		var obj=$(".tab-content-myfile").children("a:eq(0)");
		var son=$("<a href='javascript:void(0)'><span style='margin-right:5px'>搜索:'"+value+"'</span></a>");
		$(".tab-content-myfile").html("");
		$(".tab-content-myfile").append(obj);
		$(".tab-content-myfile").append(son);
		$(".tab-content-folder").html("");
		if(text=="全部文件"){
			searchload(value);
		}else if(text=="共享文件"){
			
			$.ajax({
				type:"post",
				url:"/file/searchsharefolder",
				cache:false,
				async:false,
				data:{"value":value},
				datatype:"json",
				success:function(data){
					$.each(data,function(i,item){
						newfolderfolder(item);
					})
				}
			})
			$.ajax({
				type:"post",
				url:"/file/searchsharefile",
				cache:false,
				async:false,
				data:{"value":value},
				datatype:"json",
				success:function(data){
						$.each(data,function(i,item){
							newdiv(item);
					})
				}
			})
		}else if(text=="公司文件"){
			$.ajax({
				type:"post",
				url:"/file/searchcompanyfolder",
				cache:false,
				async:false,
				data:{"value":value},
				datatype:"json",
				success:function(data){
					$.each(data,function(i,item){
						newfolderfolder(item);
					})
				}
			})
			$.ajax({
				type:"post",
				url:"/file/searchcompanyfile",
				cache:false,
				async:false,
				data:{"value":value},
				datatype:"json",
				success:function(data){
						$.each(data,function(i,item){
							newdiv(item);
					})
				}
			})
			
		}
	})
	//复原
	$(".return").click(function(){		
		var file=[];
		var folder=[];
		var obj=$(".block");
		obj.each(function(){
			if($(this).attr("filesuffix")==undefined){
				folder.push($(this).attr("directid"));
			}else{
				file.push($(this).attr("directid"));	
			}
		})
		realydelete(file,folder,"复原");	
		$(".tab-content-folder").html("");
		gabegediv();
	})
});
//查找加载
function searchload(value){
	$.ajax({
		type:"post",
		url:"/file/searchfile",
		cache:false,
		async:false,
		data:{"value":value},
		datatype:"json",
		success:function(data){
				$.each(data,function(i,item){
					newdiv(item);
			})
		}
	})
	$.ajax({
		type:"post",
		url:"/file/searchfolder",
		cache:false,
		async:false,
		data:{"value":value},
		datatype:"json",
		success:function(data){
			$.each(data,function(i,item){
				newfolderfolder(item);
			})
		}
	})
}
//加载联系人
function loadusershare(){
	$.ajax({
		type:"post",
		url:"/file/shareuserfolder",
		cache:false,
		async: false,
		success:function(data){
			$.each(data,function(i,item){
				newfolderfolder(item);
			})
		}
	})
	$.ajax({
		type:"post",
		url:"/file/shareuserfile",
		cache:false,
		async: false,
		success:function(data){
			$.each(data,function(i,item){
				newdiv(item);
			})
		}
	})
	
}
//加载公司文件
function loadcompanyshare(){
	$.ajax({
		type:"post",
		url:"/file/companyfolder",
		cache:false,
		async:false,
		datatype:"json",
		success:function(data){
			$.each(data,function(i,item){
				newfolderfolder(item);
			})
		}
	})
	$.ajax({
		type:"post",
		url:"/file/companyfile",
		cache:false,
		async:false,
		datatype:"json",
		success:function(data){
			$.each(data,function(i,item){
				newdiv(item);
			})
		}
	})
}
//展开关闭点击事件
function jian(){
	if($(".yunpan").hasClass("s")){		
		$(".yunpan").slideDown();		
		$("#one").attr("class","iconfont icon-jian");
		$(".yunpan").removeClass("s");
	}else{			
		$(".yunpan").slideUp();
		$(".yunpan").addClass("s");
		$("#one").attr("class","iconfont icon-jia");
	}
};

//展开关闭点击事件
function jian2(e){
	if($(".leixing").hasClass("s")){
		$(".leixing").slideDown();
		$("#two").attr("class","iconfont icon-jian");
		$(".leixing").removeClass("s");
	}else{
		$(".leixing").slideUp();
		$(".leixing").addClass("s");
		$("#two").attr("class","iconfont icon-jia");
	}
};
//上传文件
function upload(){
$(".fileup").trigger("click");
}
//新建文件夹
function newfolder(){
	layer.open({
		  type: 1,
		  skin: 'demo-class',
		  skin: 'yourclass',
		  offset: '200px',
		  title :'新建文件夹',
		  area: ['400px', '200px'], //宽高
		  content: $("#newfolder"),
		  closeBtn: 0,
		  btn:['确定', '取消'],
		  btnAlign: 'c', 
		  yes: function(index, layero){
		var name=$(".folder-name").val();
		if(name==""){
			var obj="\<\div style='width: 210px;height: auto; margin: 13% auto;  text-align:center;'><span style='font-size:14px'>名字不能为空！！！</span>\<\/div>";
			promptbox(obj);
			return;
		}
		var fatherid=$(".tab-content-myfile a").last().attr("fatherid");
		var path=$(".tab-content-myfile a").last().attr("path");
		if(path==undefined){
			path="undefined";
		}
			$.ajax({
				type:"post",
				url:"/file/newfolder",
				cache:false,
				async: false,
				data:{"dirId":fatherid,"path":path,"name":name},
				success:function(data){					
				}
			})
			$(".folder-name").val("");
			var fatherid=$(".tab-content-myfile a").last().attr("fatherid");
			$(".tab-content-folder").html("");
			ajax(fatherid);			
			layer.close(index);
		}
		,btn2: function(index, layero){
		    //按钮【按钮二】的回调
			layer.close(index);
		    //return false 开启该代码可禁止点击该按钮关闭
		  }
	});

}

function ajax(directid){
	$.ajax({
		type:"post",
		url:"/file/son",
		cache:false,
		async: false,
		data:{"directid":directid},
		dataType:"json",
		success:function(data){		
			$.each(data,function(i,item){
			newfolderfolder(item);
		})
		}
	}) 
		$.ajax({
				type:"post",
				url:"/file/sonfile",
				cache:false,
				async: false,
				data:{"directid":directid},
				dataType:"json",
				success:function(data){	
					$.each(data,function(i,item){
						newdiv(item);
					})
				}
			})
}
function newfolderfolder(item){
		var one=$("<div class='tab-content-folder-one' type='folder' filepath='"+item.path+"' directid='"+item.id+"' directname='"+item.text+"'></div>");	
		var four=$("<div class='select-icon' directid='"+item.id+"' style='position: absolute;'><i class='iconfont icon-success_fill' style='color:#bfd1ea; font-size: 24px;'></i></div> ");
		var two=$("<div class='tab-content-folder-one-icon'><img  width='100px' height='100px' style='visibility: hidden;'/></div>");
		var three=$("<div class='ab-content-folder-one-name'><a href='javascript:void(0)' data-id='"+item.id+"'>"+item.text+"</a></div>");											
		one.append(four);
		one.append(two);
		one.append(three); 
		$(".tab-content-folder").append(one);	
}
function newdiv(item){
	
	if(item.suffix.toLowerCase()=="mp3"){	
		var one=$("<div class='tab-content-folder-one' type='file' filepath='"+item.path+"' filesuffix='"+item.suffix+"' directid='"+item.id+"' directname='"+item.filename+"'></div>");								
		var two=$("<div class='tab-content-folder-one-icon-mp3'><img   width='100px' height='100px' style='visibility: hidden;'/></div>");				
		}else if(item.suffix.toLowerCase()=="zip"){
		var one=$("<div class='tab-content-folder-one' type='file' filepath='"+item.path+"' filesuffix='"+item.suffix+"' directid='"+item.id+"' directname='"+item.filename+"'></div>");													
		var two=$("<div class='tab-content-folder-one-icon-zip'><img   width='100px' height='100px' style='visibility: hidden;'/></div>");						
		}else if(item.suffix.toLowerCase()=="jpg"||item.suffix.toLowerCase()=="png"){
		/*	var reg = new RegExp("\\","//g");
			var path=item.path.replace(reg,"/");*/
		var one=$("<div class='tab-content-folder-one' type='file' filepath='"+item.path+"' filesuffix='"+item.suffix+"' directid='"+item.id+"' directname='"+item.filename+"'></div>");															
		var two=$("<div class='tab-content-folder-one-icon-jpg' style='width: 70px;'><img src='/file/image/"+item.path+"' height='70px'/></div>");						
		}else if(item.suffix.toLowerCase()=="mp4"){
		var one=$("<div class='tab-content-folder-one' type='file' filepath='"+item.path+"' filesuffix='"+item.suffix+"' directid='"+item.id+"' directname='"+item.filename+"'></div>");										
		var two=$("<div class='tab-content-folder-one-icon-avi'><img  width='100px' height='100px' style='visibility: hidden;'/></div>");										
		}else if(item.suffix.toLowerCase()=="cpp"){
			var one=$("<div class='tab-content-folder-one' type='file' filepath='"+item.path+"' filesuffix='"+item.suffix+"' directid='"+item.id+"' directname='"+item.filename+"'></div>");										
			var two=$("<div class='tab-content-folder-one-icon-text'><img  width='100px' height='100px' style='visibility: hidden;'/></div>");										
		}	
	var four=$("<div class='select-icon' directid='"+item.id+"' filesuffix='"+item.suffix+"' style='position: absolute;'><i class='iconfont icon-success_fill' style='color:#bfd1ea; font-size: 24px;'></i></div> ");
	var three=$("<div class='ab-content-folder-one-name'><a href='javascript:void(0)' data-id='"+item.id+"' tittle='"+item.filename+"'>"+item.filename+"</a></div>");																																
	one.append(four);
	one.append(two);
	one.append(three); 
	$(".tab-content-folder").append(one);	

}
function openfile(filesuffix,filepath){
	if(filesuffix=="undefined"){
		$(".tab-content-folder-one").trigger("dblclick");
	}else {
		fileopen(filesuffix,filepath);
	}	
}
function fileopen(filesuffix,filepath){
	if(filesuffix.toLowerCase()=="jpg"||filesuffix.toLowerCase()=="png"){
	var div=$("<div style='width:293px; height:300px;margin: 0 auto;'></div>");		
	var image=$("<img src='\\file\\image\\"+filepath+"'style='height:auto; width:300px;'>");
		div.append(image);
		width=400;
		height=500;
		$(".preview").append(div);
	}else if(filesuffix.toLowerCase()=="zip"){
		alert("不支持在线预览！！")
		return;
	}else if(filesuffix.toLowerCase()=="cpp"){
		alert("不支持在线预览！！")
		return;
	}else if(filesuffix.toLowerCase()=="mp4"){
		var div=$("<div style='width: 600px;margin: 0 auto;'></div>");	
		var video=$("<video src='\\file\\image\\"+filepath+"'  style='width: 607px;height: 409px;' controls autobuffer></video>")
		div.append(video);
		width=800;
		height=500;
		$(".preview").append(div);
	}else if(filesuffix.toLowerCase()=="mp3"){
		var div=$("<div style='width: 290px;width: 103px; margin: 8% auto;'></div>");	
		var embed=$("<embed height='50' width='100' src='\\file\\image\\"+filepath+"'>");
		div.append(embed);
		width=300;
		height=200;
		$(".preview").append(div);
	}
	layer.open({ 
	  type: 1,		
	  skin: 'demo-class',
	  skin: 'yourclass',
	  offset: '100px',
	  title :'预览',
	  area: [""+width+"px",""+height+"px"], //宽高
	  content: $(".preview"),
	  closeBtn: 0,
	  btn:['关闭'],
	  btnAlign: 'c', 
	  btn1: function(index, layero){
		layer.close(index);
		$(".preview").html("");
	    //按钮【按钮二】的回调		    
	    //return false 开启该代码可禁止点击该按钮关闭
	  }
	})
}

function copymove(fileid,filename,filepath,suffix,url){
	layer.open({
		  type: 1,
		  skin: 'demo-class',
		  skin: 'yourclass',
		  offset: '220px',
		  title :'复制到',
		  area: ['520px', '321px'], //宽高
		  content: $(".filetree"),
		  closeBtn: 0,
		  btn:['确定', '取消'],
		  btnAlign: 'c', 
		  yes: function(index, layero){
			  var id=$(".filetree-tree").tree('getSelected').id;
			  var directpath=$(".filetree-tree").tree('getSelected').path;
			  $.ajax({
				  type:"post",
				  url:url,
				  cache:false,
				  async: false,
				  data:{"fileid":fileid,"filename":filename,"filepath":filepath,"suffix":suffix,"id":id,"directpath":directpath},
				  success:function(){				  
				  }
			  })
			  var fatherid=$(".tab-content-myfile a").last().attr("fatherid");
				$(".tab-content-folder").html("");
				ajax(fatherid);			
				layer.close(index);
			}
		,btn2: function(index, layero){
		    //按钮【按钮二】的回调    
		    //return false 开启该代码可禁止点击该按钮关闭
		  }
	});
}
function newtable(item){
	var tr=$("<tr style='border-bottom: 1px solid #f2f2f2'></tr>")
	var td1=$("<td></td>")
	var div=$("<div data="+item.id+" name="+item.realName+" onclick='select(this)' class='icheckbox icheckbox_flat-green'aria-checked=false style='position:relative;'></div>")
	var input=$("<input type='checkbox' style='position: absolute; top: -20%;left: -20%;display: block;width: 140%; height: 140%;margin: 0px;padding: 0px;background: rgb(255, 255, 255);border: 0px;opacity: 0;'>")	
	var ins=$("<ins class='iCheck-helper' style='position: absolute;top: -20%;left: -20%;display: block;width: 140%;height: 140%; margin: 0px;padding: 0px;background: rgb(255, 255, 255);border: 0px;opacity: 0;'></ins>")
	var td2=$("<td><img src='../images/"+item.photo+"' style='border-radius: 50%;width: 25px; height: 25px; vertical-align: middle;'/></td>");
	var td3=$("<td>"+item.dept.name+"</td>");
	var td4=$("<td>"+item.realName+"</td>");
	var td5=$("<td>"+item.deptOffice.name+"</td>");
	var td6=$("<td>"+item.tel+"</td>");
	div.append(input);
	div.append(ins);
	td1.append(div);
	tr.append(td1);
	tr.append(td2);
	tr.append(td3);
	tr.append(td4);
	tr.append(td5);
	tr.append(td6);
	$(".contacts-tables tbody").append(tr);	
}
function newalluser(){
	 $.ajax({
		  type:"post",
		  url:"/file/user",
		  cache:false,
		  async:false,
		  datatype:"json",
		  success:function(data){
		  $.each(data,function(i,item){
			  newtable(item);
			})
		}
	  })
}
//弹出提示框
function promptbox(content){
	  layer.open({ 
		  type: 1,		
		  skin: 'demo-class',
		  skin: 'yourclass',
		  offset: '100px',
		  title :'提示',
		  area: ["300px","200px"], //宽高
		  content: content,
		  closeBtn: 0,
		  btn:['关闭'],
		  btnAlign: 'c', 
		  btn1: function(index, layero){
			layer.close(index);
			$(".preview").html("");
		    //按钮【按钮二】的回调		    
		    //return false 开启该代码可禁止点击该按钮关闭
		  }
		})

}
function gabegediv(){
	$.ajax({
		type:"post",
		url:"/file/gabgefolder",
		cache:false,
		async: false,
		datatype:"json",
		success:function(data){
			$.each(data,function(i,item){
				newfolderfolder(item);
			})
		}
	})
	$.ajax({
		type:"post",
		url:"/file/gabgefile",
		cache:false,
		async: false,
		datatype:"json",
		success:function(data){
			$.each(data,function(i,item){
				newdiv(item);
			})
		}
	})		
}
function realydelete(file,folder,type){
	$.ajax({
		type:"post",
		url:"/file/realydelete",
		cache:false,
		async: false,
		traditional:true,
		data:{"file":file,"folder":folder,"type":type},				
		success:function(data){}		
})
}